extends ../layout

block content
  .container(style='margin-top: 20px')
    if movie && movie.title
      .row
        .col-md-7.col-sm-12
          if movie.poster.indexOf('http') > -1
            img#poster(src=movie.poster, alt=movie.title, width='100%')
          else
            img#poster(src='/upload/' + movie.poster, alt=movie.title, width='100%')
        .col-md-5
          .dl-horizontal
            dt 电影名字
            dd= movie.title
            dt 导演
            dd= movie.director
            dt 国家
            dd= movie.country
            dt 上映年份
            dd= movie.year
            dt 简介
            dd= movie.summary
          .panel-heading  
            h4 评论区
          .panel-body
            ul.media-list(style='padding-left: 0')
              if comments && comments.length > 0
                each item in comments
                  if item && item.from
                    li.media(style='margin-bottom: 8px;')
                      a.comment(href='#comments', data-cid=item._id, data-tid=item.from._id)
                        img.media-object(src='', style='width: 64px;height: 64px;margin-right: 10px;')
                      .media-body
                        h5.media-heading #{item.from.nickname}
                        p #{item.content}
                        if item.replies && item.replies.length > 0
                          each reply in item.replies
                            .media
                              a.comment(href='#comments', data-cid=item._id, data-tid=item.from._id)
                                img.media-object(src='', style='width: 64px;height: 64px;margin-right: 10px;')
                              .media-body
                                h5.media-heading
                                  | #{reply.from.nickname}
                                  span.text-info &nbsp;回复&nbsp;
                                  | #{reply.to.nickname}
                                p #{reply.content}
            #comments
              form#commentForm(method='POST', action='/comment')
                input(type='hidden', name='comment[movie]', value=movie._id)
                if user
                  input(type='hidden', name='comment[from]', value=user._id)
                  input#toId(type='hidden', name='comment[tid]')
                  input#commentId(type='hidden', name='comment[cid]')
                .form-group
                  textarea.form-control(name='comment[content]', row='4')
                if user && user._id
                  button#commentSubmit.btn.btn-primary(type='submit') 提交评论
                else
                  a.navbar-link(href='#', data-toggle='modal', data-target='#signinModal') 登录后再评论
  script.
    $(function() {
      $('.comment').click(function(e) {
        var target = $(this)
        var toId = target.data('tid')
        var commentId = target.data('cid')

        $('#toId').val(toId)
        $('#commentId').val(commentId)
      })

      $('#commentSubmit').click(function(e) {
        e.preventDefault()

        $.ajax({
          type: 'POST',
          url: '/comment',
          data: $('#commentForm').serialize()
        }).done(function(results) {
          if (results.success) {
            window.location.reload()
          }
        })
      })
    })

